const utils = {
	getTimerOff(createTime) {
		let num = new Date().getTime() - createTime
		console.log(new Date().getTime() - 1615857688877)
		if (num < 60 * 60 * 1000) {
			let timer = Math.ceil((num / (60 * 1000)))
			return timer + '分钟前'
		} else if (num < 60 * 60 * 12 * 1000){
			let timer =  Math.ceil(num / (60 * 60 * 1000))
			return timer + '小时前'
		} else if (createTime) {
			let date = new Date(createTime)
			let Y = date.getFullYear();
			let M = (date.getMonth() + 1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1);
			let D = date.getDate()
			return `${Y}-${M}-${D}`
		} else {
			return ' '
		}
	},
	getTime(time) {
		console.log(time, 'time')
		if (time == 0 || !time) {
			return '00:00'
		}
		if (time < 60) {
			return `${Math.ceil(time)}`
		} else {
			const m = Math.floor(time / 60)
			const s = time % 60
			return `${m}:${Math.ceil(s)}`
		}
		
	},
	checkLogin() {
		if(uni.getStorageSync("openId")) {
			return true
		}
		uni.showToast({
			icon: 'none',
			title: '还未登录，请先登录',
			duration: 3000
		})
		uni.reLaunch({
			url: '/pages/me/index'
		})
		return false
	}
}

export default utils
